package com.zhixing.pay.listener;

import com.zhixing.common.domain.entity.UserInfo;
import com.zhixing.pay.service.WalletService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import static com.zhixing.common.constant.Constant.ZHIXING_USER_REGISTER;
import static com.zhixing.common.constant.Constant.ZHIXING_WALLET_INITIALIZE;

@Slf4j
@Component
@RequiredArgsConstructor
public class WalletListener {

    private final WalletService walletService;

    @KafkaListener(topics = ZHIXING_USER_REGISTER, groupId = ZHIXING_WALLET_INITIALIZE)
    public void initializeWallet(UserInfo userInfo) {
        log.info("支付服务调用，初始化钱包，用户id：{}", userInfo.getId());
        walletService.initializeWallet(userInfo);
    }
}
